<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="include :: header('商品列表-编辑')" />
    <style>
        .shangjia{
            color: black;
        }
        .xiajia{
            color: #c3c3c3;
        }
        img{
            width: 50px;
            height: 50px;
        }
        .t1{
            border-collapse: collapse;
        }
        .t1 td{
            line-height: 25px;
            vertical-align: middle;
        }
        /* 样式 */
        .switch {
            position: relative;
            display: inline-block;
            width: 60px;
        }
        .switch span {
            display: inline-block;
            position: relative;
            width: 40px;
            height: 20px;
            -webkit-border-radius: 10px;
            border-radius: 10px;
            background-color: #ebebeb;
            border: 2px solid #ebebeb;
            cursor: pointer;
            -webkit-transition: all .1s ease;
            -o-transition: all .1s ease;
            transition: all .1s ease;
        }
        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            -webkit-transition: .4s;
            transition: .4s;
            height: 80px;
        }

        input:checked + .slider {
            background-color: #2196F3;
        }

        input:focus + .slider {
            box-shadow: 0 0 1px #2196F3;
        }

        input:checked + .slider:before {
            -webkit-transform: translateX(26px);
            -ms-transform: translateX(26px);
            transform: translateX(26px);
        }
        .switch span:after {
            content: '';
            height: 20px;
            width: 20px;
            -webkit-border-radius: 50%;
            border-radius: 50%;
            position: absolute;
            left: 1px;
            top: -2px;
            color: #aaa;
            -webkit-transition: all .1s ease;
            -o-transition: all .1s ease;
            transition: all .1s ease;
            text-align: center;
            font-size: 13px;
            background-color: #fff;
            -webkit-box-shadow: rgba(0,0,0,.12) 0 1px 6px, rgba(0,0,0,.12) 0 1px 4px;
            box-shadow: rgba(0,0,0,.12) 0 1px 6px, rgba(0,0,0,.12) 0 1px 4px;
        }
        .zhaopai{
            float: right;
        }
        #zhaopai{
            margin-top: -10px;
        }


    </style>
</head>

<body >
<div class="row">
        <div class="card">
            <div class="card-toolbar clearfix">
                <form class="pull-left search-bar" id="keyword">
                    <div class="col-lg-12">
                        <div class="input-group">
                            <input type="hidden" class="form-control"  th:value="${shopId}" name="shopId">
                            <input type="text" class="form-control"  placeholder="请输入商品名称/原材料/描述" id="keywords" name="keywords">
                            <span class="input-group-btn">
                          <button class="btn btn-default" type="submit">搜索</button>
                        </span>
                        </div>
                    </div>
                </form>
                <div class="toolbar-btn-action pull-right">
                    <button  type="button" class="btn btn-primary" data-toggle="modal" data-target="#addDisheModal" data-whatever="@mdo"><i class="mdi mdi-plus"></i>新增</button>
                    <a class="btn btn-success m-r-5" href="#!" onclick="return shangjiaDishe()"><i class="mdi mdi-check"></i>上架</a>
                    <a class="btn btn-warning m-r-5" href="#!" onclick="return xiajiaDishe()"><i class="mdi mdi-block-helper"></i>下架</a>
                    <a class="btn btn-danger" href="javascript:void(0)" onclick="return delDishe()"><i class="mdi mdi-window-close"></i> 删除</a>
                </div>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table">
                        <tr>
                            <td>
                                <button class="btn btn-default"><a th:href="@{/dishe/getDisheByAll(shopId=${shopId})}">全部</a></button>
                                <button th:each="type:${disheType}" class="btn btn-default"  th:value="${type.disheTypeId}"><a th:href="@{/dishe/getDisheByAll(shopId=${shopId},disheTypeId=${type.disheTypeId})}">[[${type.disheTypeName}]]</a></button>
                                <button class="btn btn-warning"><a style="color: white" th:href="@{/dishe/getDisheByAll(shopId=${shopId},status=2)}">已下架</a></button>
                                <button class="btn btn-primary" data-toggle="modal" data-target="#myModal">管理分组</button>
                            </td>
                        </tr>
                    </table>
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="myModalLabel">管理分组</h4>
                                </div>
                                <div class="modal-body">
                                    <table class="table table-hover">
                                        <tr th:each="type1:${disheType}">

                                            <td style="width: 55%;line-height: 40px" class="control-label">
                                                <input type="checkbox"  class="typeId"  style="display:none" th:value="${type1.disheTypeId}"><span></span>
                                                [[${type1.disheTypeName}]]

                                            </td>
                                            <td style="color: #c3c3c3;line-height: 40px" class="control-label">[[${type1.disheNum}]]个商品</td>
                                            <td>
                                                <input type="hidden" th:value="${type1.disheTypeName}">
                                                <button class="btn btn-default typeAddDishe"  th:value="${type1.disheTypeId}" data-toggle="modal" data-target="#addDisheModal" style="border-radius: 20px">新建商品</button>
                                                <button class="btn btn-default" style="border-radius: 20px">编辑</button>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addTypeModal"><a style="color: white">添加分组</a></button>
                                    <button type="button" class="btn btn-primary" id="btn1"><a style="color: white">批量操作</a></button>
                                    <button type="button" class="btn btn-danger" style="display:none"  id="delType"><a href="javascript:void(0)" onclick="return delSelect()" style="color: white">删除</a></button>
                                    <button type="button" class="btn btn-warning" style="display:none" id="btn2"><a style="color: white">取消</a></button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <table class="table table-bordered table-hover  t1">
                        <thead>
                        <tr>
                            <th>
                                <label class="checkbox checkbox-primary">
                                    <input type="checkbox" id="check-all"><span></span>
                                </label>
                            </th>
                            <th>编号</th>
                            <th>商品</th>
                            <th>图片</th>
                            <th>价格</th>
                            <th>打包费</th>
                            <th>原材料</th>
                            <th>描述</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                          <tr th:each="dishe,disheStat : ${page.list}" th:class="${dishe.status==2?'xiajia':'shangjia'}">
                            <td>
                                <label class="checkbox checkbox-primary">
                                    <input type="hidden" class="typeId" th:value="${dishe.disheTypeId}">
                                    <input type="checkbox" class="disheId" th:value="${dishe.disheId}"><span></span>
                                </label>
                            </td>
                              <td th:text="${disheStat.count}"></td>
                              <td th:text="${dishe.disheName}"></td>
                              <td><img th:src="@{${dishe.disheImage}}"></td>
                              <td th:text="${dishe.disheMoney}"></td>
                              <td th:text="${dishe.packMoney}"></td>
                              <td th:text="${dishe.ingredient}"></td>
                              <td th:text="${dishe.describe}"></td>
                              <td th:if="${dishe.status==1}"  th:text="上架中"></td>
                              <td th:if="${dishe.status==2}"  th:text="已下架"></td>
                              <td>
                                <div th:if="${dishe.status==1}" class="btn-group">
                                    <button class="btn btn-xs btn-default"  th:onclick="|return getDishe(${dishe.disheId})|" title="编辑" data-target="#updateDisheModal" data-toggle="modal"><i class="mdi mdi-pencil"></i></button>
                                    <button class="btn btn-xs btn-default"   th:onclick="|return xiajia(${dishe.disheId},${dishe.disheTypeId})|" title="下架"  data-toggle="tooltip"><i class="mdi mdi-block-helper"></i></button>
                                </div>
                                  <div th:if="${dishe.status==2}" class="btn-group">
                                      <a class="btn btn-xs btn-default" href="#!"  title="上架" th:onclick="|return shangjia(${dishe.disheId},${dishe.disheTypeId})|" data-toggle="tooltip"><i class="mdi mdi-check"></i></a>
                                      <a class="btn btn-xs btn-default" href="javascript:void(0)" th:onclick="|return del(${dishe.disheId},${dishe.disheTypeId})|" title="删除"  data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>
                                  </div>
                              </td>
                        </tr>
                        </tbody>
                    </table>
                </div>

            </div>
        </div>

</div>
<!-- 添加分组-->
<div class="modal fade" id="addTypeModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" >新增分组</h4>
            </div>
            <div class="modal-body form-group">
                <form id="form" th:action="@{/dishe/addDisheType}"  >
                    <div class="form-group">
                        <label for="disheTypeName" class="control-label start">分组名称:</label>
                        <input type="text" class="form-control" name="disheTypeName" maxlength="20" placeholder="请输入分组名称" id="disheTypeName" >
                        <input type="hidden" id="shopId" name="shopId" th:value="${shopId}" >
                        <span id="typenamemsg" class="msg"></span>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" id="typesubmit">确定</button>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>
<!-- 关闭模态框 -->
<th:block th:include="include :: footer" />

<!--添加商品-->
<div class="modal fade" id="addDisheModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" >新增商品</h4>
            </div>
            <div class="modal-body form-group">
                <form id="myform" enctype="multipart/form-data">
                    <div class="form-group">
                        <label for="disheName" class="control-label start label-text">商品名称:</label>
                        <div class="zhaopai">
                            <p2 id="zhaopai">设为招牌</p2>
                            <label class="switch">
                                <input type="checkbox" id="zp">
                                <span class="slider"></span>
                            </label>
                        </div>
                        <input type="text" class="form-control" name="disheName" maxlength="20" placeholder="请输入商品名称" id="disheName" >
                        <label for="disheTypeId" class="control-label start">商品分类:</label><br>
                        <select class="select" name="disheTypeId" id="disheTypeId">
                            <option th:each="type:${disheType}" th:value="${type.disheTypeId}">[[${type.disheTypeName}]]</option>
                        </select><br>
                        <label for="disheImage" class="control-label start">商品图片:</label>
                        <input type="file" class="form-control" name="file" maxlength="20" id="image" >
                        <img  style="width: 100px;height: 100px;display: none;"  id="selectedImage">
                        <br>
                        <label for="disheMoney" class="control-label start">商品价格:</label>
                        <input type="text" class="form-control" name="disheMoney" maxlength="20" placeholder="请输入商品价格" id="disheMoney" >
                        <label for="ingredient" class="control-label start">原材料:</label>
                        <input type="text" class="form-control" name="ingredient" maxlength="20" placeholder="原材料" id="ingredient" >
                        <label for="describe" class="control-label">描述:</label>
                        <input type="text" class="form-control" name="describe" maxlength="20" placeholder="描述" id="describe" >
                        <label for="packMoney" class="control-label start">打包费:</label>
                        <input type="text" class="form-control" name="packMoney" maxlength="20" placeholder="打包费" id="packMoney" >
                        <input type="hidden" id="shopId1" name="shopId" th:value="${shopId}" >
                        <input type="hidden" name="disheImage" id="disheImage">
                        <input type="hidden" name="sign" id="sign">
                        <span id="typedishemsg" class="msg"></span>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" id="dishesubmit">确定</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!--编辑商品-->
<div class="modal fade" id="updateDisheModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" >编辑商品</h4>
            </div>
            <div class="modal-body form-group">
                <form id="updateform" enctype="multipart/form-data">
                    <div class="form-group">
                        <label for="disheName1" class="control-label start label-text">商品名称:</label>
                        <div class="zhaopai">
                            <p2 id="zhaopai">设为招牌</p2>
                            <label class="switch">
                                <input type="checkbox" id="zp1">
                                <span class="slider"></span>
                            </label>
                        </div>
                        <input type="text" class="form-control" name="disheName1" maxlength="20" placeholder="请输入商品名称" id="disheName1" >
                        <label for="disheTypeId1" class="control-label start">商品分类:</label><br>
                        <select class="select" name="disheTypeId1" id="disheTypeId1">
                            <option th:each="type:${disheType}" th:value="${type.disheTypeId}">[[${type.disheTypeName}]]</option>
                        </select><br>
                        <label for="disheImage1" class="control-label start">商品图片:</label>
                            <input type="file"  placeholder="请选择文件..."  class="form-control" style="display: inline-block" name="file1" maxlength="20" id="image1">
                            <img style="width: 100px;height: 100px;display: inline-block;"  id="selectedImage1">
                        <br>
                        <label for="disheMoney1" class="control-label start">商品价格:</label>
                        <input type="text" class="form-control" name="disheMoney1" maxlength="20" placeholder="请输入商品价格" id="disheMoney1" >
                        <label for="ingredient1" class="control-label start">原材料:</label>
                        <input type="text" class="form-control" name="ingredient1" maxlength="20" placeholder="原材料" id="ingredient1" >
                        <label for="describe1" class="control-label">描述:</label>
                        <input type="text" class="form-control" name="describe1" maxlength="20" placeholder="描述" id="describe1" >
                        <label for="packMoney1" class="control-label start">打包费:</label>
                        <input type="text" class="form-control" name="packMoney1" maxlength="20" placeholder="打包费" id="packMoney1" >
                        <input type="hidden" id="shopId2" name="shopId2" th:value="${shopId}" >
                        <input type="hidden" name="disheImage1" id="disheImage1">
                        <input type="hidden" name="sign1" id="sign1">
                        <input type="hidden" name="disheId" id="disheId">
                        <input type="hidden" name="typeId" id="typeId">
                        <span id="typedishemsg1" class="msg"></span>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" id="updateDishe">确定</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script >
    $(function(){
        $("#sign").val("n")
        $('#zp').click(function(){
                if($(this).is(':checked')){
                    //执行开启时的操作
                    $("#sign").val("y")
                }
                else {
                    //执行关闭时的操作
                    $("#sign").val("n")
                }
                console.log("000"+$("#sign").val())
            });
        $('#zp1').click(function(){
            if($(this).is(':checked')){
                //执行开启时的操作
                $("#sign1").val("y")
            }
            else {
                //执行关闭时的操作
                $("#sign1").val("n")
            }
            console.log("111"+$("#sign1").val())
        });
        $('#addDisheModal').on('hidden.bs.modal', function () {
            $(this).find('input[type="text"]').val('');
        })
        $('#updateDisheModal').on('hidden.bs.modal', function () {
            $(this).find('input[type="text"]').val('');
        })

        $("#btn1").click(function () {
            $(".typeId").css("display","initial")
            $("#btn1").css("display","none")
            $("#btn2").css("display","initial")
            $("#delType").css("display","initial")
        })

        $("#btn2").click(function () {
            $(".typeId").css("display","none")
            $("#btn1").css("display","initial")
            $("#btn2").css("display","none")
            $("#delType").css("display","none")
        })
        //添加商品
        $("#myform").submit(function(){
            var img=$("#image").val().substring($("#image").val().lastIndexOf('\\')+1)
            $("#disheImage").val("[[${#httpSession.getAttribute('user').shopName}]]/"+img)
            var formData = new FormData();
            formData.append('file', $('input[type=file]')[0].files[0]);
            formData.append("disheName", $("#disheName").val());
            formData.append("disheTypeId", $("#disheTypeId").val());
            formData.append("disheMoney", $("#disheMoney").val());
            formData.append("ingredient", $("#ingredient").val());
            formData.append("describe", $("#describe").val());
            formData.append("packMoney", $("#packMoney").val());
            formData.append("shopId", $("#shopId").val());
            formData.append("disheImage", $("#disheImage").val());
            formData.append("sign", $("#sign").val());
            console.log(formData)
            if(validate())
                return false;
            $.ajax({
                type: "post",
                url: "[[@{/dishe/addDishe}]]",
                data: formData,
                processData: false,
                contentType: false,
                success: function (result) {
                    if (result > 0) {
                        alert("添加成功");
                        window.location.href = "[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                    } else {
                        alert("数据提交失败！");
                        return false;
                    }
                },
                error: function (result) {
                    alert("error"+result);
                }
            })

            return false;
        })


        $("#form").submit(function(){
            if(validate())
                return false;
            $.ajax({
                type: "get",
                url: "[[@{/dishe/addDisheType}]]",
                data: $('#form').serialize(),
                success: function (result) {
                    if (result > 0) {
                        alert("添加成功");
                        window.location.href = "[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                    } else {
                        alert("添加失败！");
                        return false;
                    }
                },
                error: function (result) {
                    alert("error"+result);
                }
            })

            return false;
        })


        $(".typeAddDishe").click(function () {
            console.log($(this).val())
            console.log($(this).prev().val())
            $("#disheTypeId").val($(this).val())

        })
        $("#image").on("change", function() {
            $("#selectedImage").css("display","inline-block")
            const fileInput = $("#image")[0];
            const selectedImage1 = $("#selectedImage")[0];
            const file = fileInput.files[0];
            const reader = new FileReader();
            reader.onload = function(event) {
                selectedImage.src = event.target.result;
            };
            reader.readAsDataURL(file);
        });

        $("#image1").on("change", function() {
            const fileInput = $("#image1")[0];
            const selectedImage1 = $("#selectedImage1")[0];
            const file = fileInput.files[0];
            const reader = new FileReader();
            reader.onload = function(event) {
                selectedImage1.src = event.target.result;
            };
            reader.readAsDataURL(file);
        });
        //表单校验
        function validate(){
            var flag = false;
            if($("#username").val()==""){
                $("#usernamemsg").text("用户名不能为空");
                flag = true;
            }
            if($("#password").val()==""){
                $("#passwordmsg").text("密码不能为空");
                flag = true;
            }
            return flag;

        }

    });

    //编辑显示商品
    function getDishe(id) {
        $.ajax({
            url: "[[@{/dishe/getDisheById}]]",
            type: "POST",
            data: {"disheId": id},
            success: function(result) {
                console.log(result)
                if (result.sign=="y"){
                    $("#zp1").prop("checked", true)
                }
                if (result.sign=="n"){
                    $("#zp1").prop("checked", false)
                }
                // 4. 在模态框中展示查询结果
                $("#disheName1").val(result.disheName)
                $("#disheTypeId1").val(result.disheTypeId)
                $("#disheMoney1").val(result.disheMoney)
                $("#ingredient1").val(result.ingredient)
                $("#describe1").val(result.describe)
                $("#packMoney1").val(result.packMoney)
                $("#shopId2").val(result.shopId)
                $("#disheImage1").val(result.disheImage)
                $("#sign1").val(result.sign)
                $("#selectedImage1").attr('src', result.disheImage);
                $("#disheId").val(result.disheId)
                $("#typeId").val(result.disheTypeId)
            },
            error: function() {
                alert("请求失败");
            }
        });
    }
    //编辑修改
    $("#updateform").submit(function(){
        var formData1=new FormData()
        var img;
        if ($("#image1").val()!==''){
            img="[[${#httpSession.getAttribute('user').shopName}]]/"+$("#image1").val().substring($("#image1").val().lastIndexOf('\\')+1)
            formData1.append('file', $("#image1")[0].files[0]);
        }else {
            img=$("#selectedImage1").attr('src')
        }
        $("#disheImage1").val(img)

        formData1.append('disheId', $("#disheId").val());
        formData1.append("disheName", $("#disheName1").val());
        formData1.append("disheTypeId", $("#disheTypeId1").val());
        formData1.append("disheMoney", $("#disheMoney1").val());
        formData1.append("ingredient", $("#ingredient1").val());
        formData1.append("describe", $("#describe1").val());
        formData1.append("packMoney", $("#packMoney1").val());
        formData1.append("shopId", $("#shopId1").val());
        formData1.append("disheImage", $("#disheImage1").val());
        formData1.append("sign", $("#sign1").val());
        formData1.append("typeId", $("#typeId").val());
        console.dir(formData1)
        $.ajax({
            type: "post",
            url: "[[@{/dishe/updateDishe}]]",
            data: formData1,
            processData: false,
            contentType: false,
            success: function (result) {
                if (result > 0) {
                    alert("修改成功");
                    window.location.href = "[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                } else {
                    alert("修改失败！");
                    return false;
                }
            },
            error: function (result) {
                alert("error"+result);
            }
        })
        return false;
    })

    //单个删除商品
    function del(id) {
        var typeId=$(this).prev().val()
        if (confirm("您确定要删除吗?")) {
            $.post("[[@{/dishe/delDishe}]]",{"idStr":id,"typeIds":typeId},function(data){
                if(data>0){
                    alert("删除成功！");
                    window.location.href="[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                }else{
                    alert("删除失败");
                }
            });
        }
    }


    //批量删除商品
    function delDishe() {
        var typeIds="";
        var ids = "";
        var Checkbox = false;
        $(".disheId").each(function () {
            if (this.checked) {
                //获取选中复选框的主键值，用逗号隔开  12,13,14
                ids+= this.value+",";
                typeIds+=$(this).prev().val()+",";
                Checkbox = true;
            }
        });
        if (Checkbox) {
            //去除尾部逗号
            ids = ids.substring(0,ids.lastIndexOf(','));
            typeIds = typeIds.substring(0,typeIds.lastIndexOf(','));
            if (!confirm("您确认要删除选中的内容吗？"))
                return false;
            $.ajax({
                type: "post",
                url: "[[@{/dishe/delDishe}]]",
                data:{"idStr":ids,"typeIds":typeIds},
                success: function (result) {
                    if (result > 0) {
                        alert("数据删除成功！");
                        window.location.href="[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                    } else {
                        alert("数据删除失败！！");
                        return false;
                    }
                }
            });
        }
        else {
            alert("请选择您要删除的内容!");
            return false;
        }
    }
    //批量删除分类
    function delSelect() {
        var ids = "";
        var Checkbox = false;
        $(".typeId").each(function () {
            if (this.checked) {
                //获取选中复选框的主键值，用逗号隔开  12,13,14
                ids+= this.value+",";
                Checkbox = true;
            }
        });
        if (Checkbox) {
            //去除尾部逗号
            ids = ids.substring(0,ids.lastIndexOf(','));
            if (!confirm("您确认要删除选中的内容吗？"))
                return false;
            $.ajax({
                type: "post",
                url: "[[@{/dishe/delDisheType?idStr=}]]" + ids,
                success: function (result) {
                    if (result > 0) {
                        alert("数据删除成功！");
                        window.location.href="[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                    } else {
                        alert("数据删除失败！！");
                        return false;
                    }
                }
            });
        }
        else {
            alert("请选择您要删除的内容!");
            return false;
        }
    }
    //下架
    function xiajia(id,typeId) {
        console.log(typeId)
        if (confirm("您确定要下架吗?")) {
            $.post("[[@{/dishe/xiajiaDishe}]]",{"idStr":id,"typeIds":typeId},function(data){
                if(data>0){
                    alert("下架成功！");
                    window.location.href="[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                }else{
                    alert("下架失败");
                }
            });
        }
    }

    function xiajiaDishe() {
        var typeIds="";
        var ids = "";
        var Checkbox = false;
        $(".disheId").each(function () {
            if (this.checked) {
                //获取选中复选框的主键值，用逗号隔开  12,13,14
                ids+= this.value+",";
                typeIds+=$(this).prev().val()+",";
                Checkbox = true;
            }
        });
        if (Checkbox) {
            //去除尾部逗号
            ids = ids.substring(0,ids.lastIndexOf(','));
            typeIds = typeIds.substring(0,typeIds.lastIndexOf(','));
            if (!confirm("您确认要下架选中的内容吗？"))
                return false;
            $.ajax({
                type: "post",
                url: "[[@{/dishe/xiajiaDishe}]]",
                data:{"idStr":ids,"typeIds":typeIds},
                success: function (result) {
                    if (result > 0) {
                        alert("下架成功！");
                        window.location.href="[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                    } else {
                        alert("下架失败！！");
                        return false;
                    }
                }
            });
        }
        else {
            alert("请选择您要下架的商品!");
            return false;
        }
    }
    //上架
    function shangjia(id,typeId) {
        if (confirm("您确定要上架吗?")) {
            $.post("[[@{/dishe/shangjiaDishe}]]",{"idStr":id,"typeIds":typeId},function(data){
                if(data>0){
                    alert("上架成功！");
                    window.location.href="[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                }else{
                    alert("上架失败");
                }
            });
        }
    }
    function shangjiaDishe() {
        var typeIds="";
        var ids = "";
        var Checkbox = false;
        $(".disheId").each(function () {
            if (this.checked) {
                //获取选中复选框的主键值，用逗号隔开  12,13,14
                ids+= this.value+",";
                typeIds+=$(this).prev().val()+",";
                Checkbox = true;
            }
        });
        if (Checkbox) {
            //去除尾部逗号
            ids = ids.substring(0,ids.lastIndexOf(','));
            typeIds = typeIds.substring(0,typeIds.lastIndexOf(','));
            if (!confirm("您确认要上架选中的内容吗？"))
                return false;
            $.ajax({
                type: "post",
                url: "[[@{/dishe/shangjiaDishe}]]",
                data:{"idStr":ids,"typeIds":typeIds},
                success: function (result) {
                    if (result > 0) {
                        alert("上架成功！");
                        window.location.href="[[@{/dishe/getDisheByAll(shopId=${shopId})}]]";
                    } else {
                        alert("上架失败！！");
                        return false;
                    }
                }
            });
        }
        else {
            alert("请选择您要上架的商品!");
            return false;
        }
    }

</script>
</body>
</html>